{template 'common/header'}
<ul class="nav nav-tabs">
	<li {if $op == 'post'}class="active"{/if}><a href="{php echo $this->wurl('book', array('op' => 'post'))}">添加课程</a></li>
	<li {if $op == 'display'}class="active"{/if}><a href="{php echo $this->wurl('book')}">课程列表</a></li>
</ul>
{if $op == 'display'}
<style>
th{
	text-align: center !important;
}
td{
	text-align: center !important;
	white-space: normal !important;
	word-break: break-all !important;
	vertical-align: middle !important;
}
</style>
<a class="btn btn-sm btn-success" href="../addons/junsion_listenbook/excel/example.xls">下载样例</a>
<style>
	.masklayer{ display: none; width: 100%; height: 100%; position: fixed; z-index: 1000; top: 0px; left: 0px; background: rgba(0,0,0,.6);}
	.mask{ display: none; width: 460px; height: auto; overflow: hidden; position: fixed; z-index: 2000; left: 50%; margin-left: -230px; background: #fff; top: 20%;}
	.mask .title{ width: 100%; height: 40px; line-height: 40px; background:#467ab3; position: relative; z-index: 10;}
	.mask .title span{ margin-left: 15px; color: #fff; font-size: 14px;}
	.mask .title .close{ width: 40px; height: 40px; position: absolute; display: block; top: 7px; right: -15px;color:#fff; z-index: 20;}
	.maskMain{  padding: 0px; height: auto; overflow: hidden; text-align: center; padding-bottom: 30px;}
	.maskMain a{ width: 40%; height: 46px; line-height: 46px; text-align: center; display: inline-block; background: #467ab3; color: #fff; border: 1px solid #000; margin: 30px 15px 0px 15px;}
</style>
<div class="masklayer" onclick="javascript:close1();" style="display: none;"></div>
<div class="mask maskOuter" style="display: none;">
			<p class="title">
				<span>批量导入模板</span>
				<em class="close" onclick="javascript:close1();">X</em>
			</p>
			<div class="maskMain">
				<form style="display: inline-block;width: 400px;" action="{php echo $this->createWebUrl('import')}" method="post" enctype="multipart/form-data" class="form-inline">
				<input type="hidden" id="rowid" name="id" value=""/>
				<input type="file" name='txtfile' class="form-control">
				<button class="btn btn-info" type="submit">导入</button>
				</form>
			</div>
</div>

<script>
function importrow(id){
	$('#rowid').val(id)
	$(".mask").show();
	$(".masklayer").show();
}
function close1(){
	$(".maskOuter").hide();
	$(".masklayer").hide();
}
</script>
<form action="" method="get" class="form-horizontal" role="form">
	<div class="panel panel-info">
        <div class="panel-heading">筛选</div>
			<div class="panel-body">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="{php echo $this->modulename}" />
                <input type="hidden" name="do" value="book" />
				<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">课程名称</label>
	                <div class="col-xs-12 col-sm-2 col-lg-2">
	                    <input class="form-control" name="title" type="text" value="{$title}" placeholder="">
	                </div>
                	<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"></label>
                    <div class=" col-xs-12 col-sm-3 col-lg-3">
                        <button class="btn btn-sm btn-default" ><i class="fa fa-search"></i> 搜索</button>
                   	</div>
				</div>
			</div>
        </div>
</form>			
<div class="main">
	<div class="cate" style="background: white;">
		<table class="table table-hover">
			<thead>
				<tr>
					<th>ID</th>
					<th>排序</th>
					<th>图片</th>
					<th>名称</th>
					<th>价格</th>
					<th>原价</th>
					<th>首页显示</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
			{loop $list $item}
				<tr>
					<td>{$item['id']}</td>
					<td>{$item['sort']}</td>
					<td><img src="{php echo toimage($item['thumb'])}" style="width:100px;"></td>
					<td>{$item['title']}</td>
					<td>{$item['price']}</td>
					<td>{$item['original']}</td>
					<td>{if $item['isshow']}<label class="label label-success">显示</label>{else}<label class="label label-default">隐藏</label>{/if}</td>
					<td>
						<a class="btn btn-sm btn-default" href="{php echo $this->wurl('book', array('op' => 'post', 'id' => $item['id']))}"><i class='fa fa-edit'></i>编辑</a>
						<a class="btn btn-sm btn-success" href="{php echo $this->wurl('directory', array('op' => 'display', 'bid' => $item['id']))}"><i class='fa fa-edit'></i>目录</a>
						<br/>
						<a class="btn btn-sm btn-info" href="javascript:importrow('{$item['id']}');">导入目录章节</a>
						<a onclick="return confirm('确定删除吗？');return false;" href="{php echo $this->wurl('book',array('op'=>'del','id'=>$item['id']))}" class="btn btn-sm btn-danger"><i class="fa fa-remove"></i> 删除</a>
					</td>
				</tr>
			{/loop}
			</tbody>
		</table>
		{$pager}
	</div>
</div>
{/if}
{if $op == 'post'}
<style>
.settings{
	display: none;
}
</style>
<ul class="nav nav-tabs" id="snav">
	<li class="active"><a>课程设置</a></li>
	{if $cfg['status']}
	<li><a>分销设置</a></li>
	<li><a>分销海报设置</a></li>
	{/if}
</ul>
<script>
$('#snav li').click(function(){
	$('#snav li').removeClass('active');
	$(this).addClass('active');
	$('.settings').hide();
	$('.settings').eq($(this).index()).show();
});
</script>
<div class="main">
	<form action="" method="post" class="form-horizontal form">
		<input type="hidden" name="id" value="{$id}" />
        <div class="panel panel-default settings" style="display: block;">
            <div class="panel-heading">
                详情设置
            </div>
            <div class="panel-body">
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">名称</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="title" class="form-control" value="{$item['title']}" />
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">封面</label>
                    <div class="col-sm-9 col-xs-12">
                    	{php echo tpl_form_field_image('cover',$item['cover']);}
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">图片</label>
                    <div class="col-sm-9 col-xs-12">
                    	{php echo tpl_form_field_image('thumb',$item['thumb']);}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">开课时间</label>
                    <div class="col-sm-9 col-xs-12">
                        <label class="radio-inline"><input type="radio" name="start_day" value="1" {if $id}disabled{/if} {if $item['start_day']==1}checked{/if}>周一</label>
                        <label class="radio-inline"><input type="radio" name="start_day" value="2" {if $id}disabled{/if} {if $item['start_day']==2}checked{/if}>周二</label>
                        <label class="radio-inline"><input type="radio" name="start_day" value="3" {if $id}disabled{/if} {if $item['start_day']==3}checked{/if}>周三</label>
                        <label class="radio-inline"><input type="radio" name="start_day" value="4" {if $id}disabled{/if} {if $item['start_day']==4}checked{/if}>周四</label>
                        <label class="radio-inline"><input type="radio" name="start_day" value="5" {if $id}disabled{/if} {if $item['start_day']==5}checked{/if}>周五</label>
                        <label class="radio-inline"><input type="radio" name="start_day" value="6" {if $id}disabled{/if} {if $item['start_day']==6}checked{/if}>周六</label>
                        <label class="radio-inline"><input type="radio" name="start_day" value="0" {if $id}disabled{/if} {if $item['start_day']==0}checked{/if}>周日</label>
                        <label class="radio-inline"><input type="radio" name="start_day" value="-1" {if $id}disabled{/if} {if $item['start_day']==-1}checked{/if}>随时</label>
                    	<span class="help-block">开课时间选择后将无法更改</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">精选书单</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="booktips" class="form-control" value="{if $item['booktips']}{$item['booktips']}{else}精选书单{/if}" />
                        <div class="help-block">精选书单自定义文字</div>
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">简述</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="des" class="form-control" value="{$item['des']}" />
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">导师</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="author" class="form-control" value="{$item['author']}" />
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">价格</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="price" class="form-control" value="{$item['price']}" />
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">原价</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="original" class="form-control" value="{$item['original']}" />
                    </div>
                </div>
{if $this->module['config']['multiaccount']}
<style>
#wechats{
	border: 1px solid green;
    border-radius: 5px;
    padding: 5px;
    margin-top: 5px;
    height: auto;
    width: 100%;
}
.label-wechat{
	margin-right: 5px;
	display: inline-grid;
}
</style>                
                <div class="form-group">
				<label class="col-xs-12 col-sm-3 col-md-2 control-label">关联公众号</label>
				<div class="col-sm-9">
					<select class="form-control" id="sel_weid" name="sel_tags">
			            <option value="0">请关联公众号</option>
			            {loop $wechats $c}
			            <option value="{$c['uniacid']}">{$c['name']}</option>
			        	{/loop}
			        </select>
			        <a onclick="addwechat()" class="btn btn-primary btn-sm">添加公众号</a>
					<div id="wechats">{loop $wechats $c}{if in_array($c['uniacid'],$wids)}<label class="label label-info label-wechat" data-id="{$c['uniacid']}">{$c['name']}</label>{/if}{/loop}</div>
					{loop $wechats $c}
					{if in_array($c['uniacid'],$wids)}
					<input type="hidden" name="weids[]" id="wechats{$c['uniacid']}" value="{$c['uniacid']}">
					{/if}
					{/loop}
					<span class="help-block">点击公众号标签则删除关联对应的公众号</span>
					<span class="help-block">若不选择关联公众号则只在当前公众号有效</span>
					<span class="help-block">关联的公众号和当前公众号必须绑定同一个<a href='https://open.weixin.qq.com/' target="_blank">开放平台</a>，否则异常！</span>
					<span class="help-block">新关联的公众号，请到粉丝管理去同步所有粉丝</span>
				</div>
			</div>
<script>
function addwechat(){
	var weid = $('#sel_weid').val();
	if(weid == 0)return false;
	var weid_name = $('#sel_weid').find("option:selected").text();
	if($('#wechats'+weid).length > 0) return;
	$('#wechats').append("<label class='label label-info label-wechat' data-id='"+weid+"' style='display: -webkit-inline-box;'>"+weid_name+"</label>");
	$('#wechats').after('<input type="hidden" name="weids[]" id="wechats'+weid+'" value="'+weid+'">');
	$('#sel_weid').val('0');
	$('.label-wechat').click(function(){
		$(this).remove();
		$('#parking'+$(this).attr('data-id')).remove();
	});
}
$('.label-wechat').click(function(){
	$(this).remove();
	$('#wechats'+$(this).attr('data-id')).remove();
});
</script>
{/if}        
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">首页显示</label>
                    <div class="col-sm-9 col-xs-12">
                        <label class="radio-inline"><input type="radio" name="isshow" value="0" {if $item['isshow']==0}checked{/if}>隐藏</label>
                        <label class="radio-inline"><input type="radio" name="isshow" value="1" {if $item['isshow']==1}checked{/if}>显示</label>
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">标签</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="label" class="form-control" value="{$item['label']}" />
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">试听按钮颜色</label>
                    <div class="col-sm-9 col-xs-12">
                    	{php echo tpl_form_field_color('ltcolor',$item['ltcolor']);}
                    	<span class="help-block">颜色包括报名按钮外层颜色和字体颜色</span>
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">报名按钮颜色</label>
                    <div class="col-sm-9 col-xs-12">
                    	{php echo tpl_form_field_color('btncolor',$item['btncolor']);}
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">购买推送消息</label>
                    <div class="col-sm-9 col-xs-12">
                    	<textarea class="form-control" rows="3" cols="" name="paydes">{$item['paydes']}</textarea>
                    	<span class="help-block">购买后扫码推送消息提示</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">课程学时</label>
                    <div class="col-sm-9 col-xs-12">
                        <div class='input-group'>
							<div class='input-group-addon'>学时数</div>  
                        	<input type="number" name="class_num" class="form-control" value="{$item['class_num']}" />
							<div class='input-group-addon'>节 打卡数</div>  
                        	<input type="number" name="clock_num" class="form-control" value="{$item['clock_num']}" />
							<div class='input-group-addon'>次</div>  
                        </div>
                        <span class="help-block">会员打卡数达到设置的的次数后，将可以申请奖学金</span>
                        <span class="help-block">若打卡数为0或不设置则表示不返还奖学金</span>
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="number" name="sort" class="form-control" value="{$item['sort']}" />
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">详情图片</label>
                    <div class="col-sm-9 col-xs-12">
                    	{php echo tpl_form_field_image('tabthumb',$item['tabthumb']);}
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">详情介绍</label>
                    <div class="col-sm-9 col-xs-12">
                    	{php echo tpl_ueditor('introduce',$item['introduce'],array('height'=>'360'));}
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">精选书单</label>
                    <div class="col-sm-9 col-xs-12">
                    	{php echo tpl_ueditor('selection',$item['selection'],array('height'=>'360'));}
                    </div>
                </div>
			</div>
		</div>
		{if $cfg['status']}
		<div class='settings panel panel-default'>
			<div class='panel-heading'>分销设置</div>
			<div class='panel-body'>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">分销机制</label>
					<div class="col-sm-9">
						<label><input type="radio" name="commission[status]" {if empty($item['commission']['status'])}checked="checked"{/if} value="0"> 按照全局设置</label>
						<label style="margin-left: 10px;"><input type="radio" name="commission[status]" {if $item['commission']['status']==1}checked="checked"{/if} value="1"> 按照课程设置</label>
						<label style="margin-left: 10px;"><input type="radio" name="commission[status]" {if $item['commission']['status']==2}checked="checked"{/if} value="2"> 关闭</label>
						<span class="help-block">关闭后，这个课程不参与分销返现</span>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">一级分佣比例</label>
					<div class="col-sm-9">
						<div class="input-group">
						<input class="form-control" name="commission[rate]" type="number" value="{$item['commission']['rate']}">
						<span class="input-group-addon">%</span>
						</div>
					</div>
				</div>
		        <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">二级分佣比例</label>
					<div class="col-sm-9">
						<div class="input-group">
						<input class="form-control" name="commission[rate2]" type="number" value="{$item['commission']['rate2']}">
						<span class="input-group-addon">%</span>
						</div>
					</div>
				</div>
		        <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">三级分佣比例</label>
					<div class="col-sm-9">
						<div class="input-group">
						<input class="form-control" name="commission[rate3]" type="number" value="{$item['commission']['rate3']}">
						<span class="input-group-addon">%</span>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class='settings'>
		{template 'poster1'}
		</div>
		{/if}
        <input name="submit" type="submit" value="提交" class="btn btn-sm btn-primary span3">
        <input type="hidden" name="token" value="{$_W['token']}" />
	</form>
</div>
{/if}
{template 'common/footer'}
